package com.jxs.android.ges;

import java.util.List;
import java.util.Map;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.jxs.android.ges.db.CustomerHolder;
import com.jxs.android.weiget.TopBar;

public class GetCustomerList extends AbstractActivity {
	protected ListView listView;
	private SimpleAdapter adapter;
	private List<Map<String, String>> list;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		initTopBar(savedInstanceState, R.layout.bu_get_customer_list);
		listView = (ListView) findViewById(R.id.common_listview);
		list = CustomerHolder.queryAll(true);
		adapter = new SimpleAdapter(this, list, R.layout.bu_filter_common_row, new String[] { "content" }, new int[] { R.id.row_content });
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
				Map<String, String> items = list.get(position);
				Intent intent = new Intent();
				Bundle bundle = new Bundle();
				bundle.putString("id", items.get("id"));
				bundle.putString("content", items.get("content"));
				intent.putExtras(bundle);
				setResult(RESULT_OK, intent);
				finish();
			}
		});
	}

	@Override
	public void topBarLogic(TopBar topBar) {
		super.topBarLogic(topBar);
		topBar.hindSpinnerBtn();
		topBar.setTitle("选择客户");
		topBarReturn(topBar);
	}

}
